<?php
/** 
 * 订单汇总商品表模型
 *
 * @author   xionggan
 * @date     2019-09-17
 */

namespace app\common\model;

use think\Db;
use think\Model;

class CoreOrderProduct extends Model
{
    protected $name  = 'core_order_product';
    protected $error = null;

    const SERVICE_STATUS_0 = 0;
    const SERVICE_STATUS_1 = 1;

    const DELIVERY_STATUS_0 = 0;
    const DELIVERY_STATUS_1 = 1;
    const DELIVERY_STATUS_2 = 2;
    const DELIVERY_STATUS_3 = 3;

    const VERIFY_STATUS_0 = 0;
    const VERIFY_STATUS_1 = 1;
    const VERIFY_STATUS_2 = 2;

    // 追加属性
    protected $append = [
        'product_img_r'
    ];

    /**
     * 获取订单商品发货状态映射
     * @return  array   状态映射表
     */
    public function getDeliveryStatusMap()
    {
        return [
            self::DELIVERY_STATUS_0  => '待发货',
            self::DELIVERY_STATUS_1  => '部分发货',
            self::DELIVERY_STATUS_2  => '已发货',
            self::DELIVERY_STATUS_3  => '已收货',
        ];
    }

    /**
     * 获取订单商品核销状态映射
     * @return  array   状态映射表
     */
    public function getVerifyStatusMap()
    {
        return [
            self::VERIFY_STATUS_0  => '待核销',
            self::VERIFY_STATUS_1  => '部分核销',
            self::VERIFY_STATUS_2  => '已核销',
        ];
    }

    /**
     * 获取错误信息
     * @return  string   错误信息
     */
    public function getError()
    {
        return $this->error;
    }

    public function getProductImgRAttr($value, $data)
    {
        return get_img_url($data['product_img'], 300);
    }

    public function getCreateTimeAttr($value, $data)
    {
        return date('Y-m-d H:i:s', $data['create_time']);
    }

    public function ServiceProduct()
    {
        return $this->hasOne('app\common\model\CoreOrderServiceProduct', 'order_pid', 'order_pid');
    }

}
